package
{
	import flash.display.Graphics;
	import flash.display.GraphicsPathCommand;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;

	/**
	 * ...
	 * @author jianping.shenjp
	 */
	public class Main extends Sprite
	{
		private var move:Sprite;
		
		private var circle:Shape;
		public function Main():void
		{
			if (stage)
				init();
			else
				addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(e:Event = null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			circle = new Shape();
			circle.graphics.beginFill(0x0000FF);
			circle.graphics.drawCircle(40, 40, 40);
			circle.x = 10;
			addChild(circle);

			var bg:Sprite = new Sprite();
			
			var g:Graphics =  bg.graphics;
			g.beginFill(0xFF0000);
			g.drawRect(0, 0, 100, 100);
			g.endFill();
			bg.x = 30;
			this.addChild(bg);
			
			bg.addChild(circle);
			
			g.beginFill(0xFF0000);
			g.drawCircle(-10, 0, 3);
			g.endFill();
			var point1:Point = new Point(0, 0);
			trace(circle.hitTestPoint(point1.x, point1.y, true)); // false
			trace(circle.hitTestPoint(point1.x, point1.y, false)); // false
			trace(circle.globalToLocal(point1)); // [x=-10, y=0]
			
			g.beginFill(0xFF0000);
			g.drawCircle(0, 1, 3);
			g.endFill();
			
			var point2:Point = new Point(10, 1);
			trace(circle.hitTestPoint(point2.x, point2.y, true)); // false
			trace(circle.hitTestPoint(point2.x, point2.y, false)); // true
			trace(circle.globalToLocal(point2)); // [x=0, y=1]

			g.beginFill(0xFF0000);
			g.drawCircle(20, 20, 3);
			g.endFill();
			
			var point3:Point = new Point(30, 20);
			trace(circle.hitTestPoint(point3.x, point3.y, true)); // true
			trace(circle.hitTestPoint(point3.x, point3.y, false)); // true
			trace(circle.globalToLocal(point3)); // [x=20, y=20]

			//initMove();
			initEnterFrame();
		}
		
		private function initEnterFrame():void 
		{
			this.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
		}
		
		private function enterFrameHandler(e:Event):void 
		{
			//trace(mouseX,mouseY,circle);
			if (circle && circle.hitTestPoint(mouseX, mouseY, false))
			{
				trace("hit");
			}
		}
		
		//private function initMove():void 
		//{
			//move = new Sprite();
			//move.startDrag(true);
		//}

	}

}